package com.hailiao.beidou.message.ui.page.splash

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.booleanResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.hailiao.beidou.message.R
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootNavGraph

/**
 * 启动页
 * @Author d10ng
 * @Date 2023/11/13 11:28
 */
@RootNavGraph(start = true)
@Destination
@Composable
fun SplashScreen(
    model: SplashScreenViewModel = viewModel()
) {
    LaunchedEffect(model) { model.init() }
    SplashScreenView()
}

@Composable
private fun SplashScreenView() {
    Box(
        modifier = Modifier
            .fillMaxSize()
    ) {
        // 背景
        Image(
            painter = painterResource(id = R.drawable.bg_splash),
            contentDescription = null,
            modifier = Modifier
                .fillMaxSize(),
            contentScale = ContentScale.Crop
        )
        // 标语
        Image(
            painter = painterResource(id = R.mipmap.img_splash_slogan),
            contentDescription = null,
            modifier = Modifier
                .padding(horizontal = 64.dp)
                .padding(bottom = 64.dp)
                .fillMaxWidth()
                .align(Alignment.Center),
        )
        // 是否显示LOGO
        if (booleanResource(R.bool.is_show_company_info)) {
            // LOGO
            Image(
                painter = painterResource(id = R.mipmap.img_splash_logo),
                contentDescription = null,
                modifier = Modifier
                    .padding(bottom = 50.dp)
                    .width(174.dp)
                    .align(Alignment.BottomCenter),
                contentScale = ContentScale.Fit
            )
        }
    }
}

@Preview
@Composable
private fun SplashScreenPreview() {
    SplashScreenView()
}